<template>
  <!-- <transition name='slide'
              mode='out-in'> -->
  <music-list :title="songSheet.title"
              :avatar='songSheet.cover'
              :songs='songList'></music-list>
  <!-- </transition> -->
</template>

<script>
// 歌单列表
import { mapState } from 'vuex'
import { awaitWrap } from 'common/js/dom'
import { getSongSheet } from 'api/recommend'
import MusicList from 'components/music-list/music-list'
import { ERR_OK } from 'api/config'
import { createSong } from 'common/js/song'
export default {
  data () {
    return {
      songList: []
    }
  },
  methods: {
    async _getSongSheet () {
      console.log(arguments)
      if (!this.songSheet.content_id) return this.$router.replace('/rank')
      // 请求数据
      const [err, data] = await awaitWrap(getSongSheet(this.songSheet.content_id))
      if (data.code === ERR_OK) {
        this.songList = await this._normalSong(data.cdlist[0].songlist)
      }
      if (err) { }
    },
    async _normalSong (res) {
      let ret = []
      for (let i = 0; i < res.length; i++) {
        let obj = await createSong(res[i], i)
        ret.push(obj)
      }
      return ret
    }
  },
  computed: {
    ...mapState([
      'songSheet'
    ])
  },
  created () {
    this._getSongSheet()
  },
  mounted () {
    console.log(this.songSheet)
    if (!this.songSheet) this.$router.back()
  },
  components: {
    MusicList
  }
}
</script>

<style scoped lang='stylus'  rel='stylesheet/stylus'>
@import '~common/stylus/variable'
.singerDetail-page
  position fixed
  top 0
  left 0
  right 0
  bottom 0
  background $color-background
.slide-enter-active, .slide-leave-active
  transition all 0.35s
.slide-enter, .slide-leave-to
  transform translate3d(100%, 0, 0)
</style>
